package com.weakteam.orderonline.adminconsole.gwt.client.widget;


import com.google.gwt.user.client.ui.HTML;
import com.weakteam.orderonline.adminconsole.gwt.client.domain.Place;
import com.weakteam.orderonline.adminconsole.gwt.client.util.WebContext;


/**
 * Created by Max on 02.04.2014.
 */
public class PlacesBox extends HTML {

    private Place place;

    private Boolean selected;

    public PlacesBox(Place place) {
        this.place = place;
        this.selected = false;
        this.setData(place);
        this.setStyleName("category-item");
    }

    public Boolean isSelected() {
        return selected;
    }
    public Place getPlace(){
        return this.place;
    }
    public int getPlaceId() {
        return this.place.getId();
    }


    public void setData(Place data) {
        String qrText = "{\"ip\":\"81.177.48.54\",\"port\":\"8080\",\"customerId\":\"TestRest\",\"placeId\":"+place.getId()+"}";
        String QRCodeImageUrl = WebContext.getInstance().getRootContext() + "getQRCodeImage?qrText="+ qrText;
        String html = "<div>"+ data.getName()+"</div>" +
                      "<img onmousedown=\"return false\" class=\"category-item\"" +
                      "src=\""+ QRCodeImageUrl + "\">";
        this.setHTML(html);
    }

    public void setSelected(Boolean selected) {
        this.selected = selected;
        if (selected) {
            this.addStyleName("content-item-selected");
        } else {
            this.removeStyleName("content-item-selected");
        }
    }

}